package com.example.pufang.controller;

import com.example.common.CommonResult;
import com.example.common.PageParamRequest;
import com.example.pufang.pojo.ImgModel;
import com.example.pufang.service.FeedbackService;
import com.example.pufang.service.ImgModelService;
import com.example.pufang.vo.PageListVo;
import io.swagger.annotations.Api;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/imgModel")
@CrossOrigin
@Api(tags = "web公用图片接口")
public class ImgModelController {


    @Autowired
    private ImgModelService imgModelService;

    @Operation(summary = "获取分页用户列表")
    @GetMapping("getListByPage")
    public CommonResult<PageListVo> getListByPage(PageParamRequest pageParamRequest, String searchTitle) {
        return CommonResult.success(imgModelService.getListByPage(pageParamRequest, searchTitle));
    }

    @Operation(summary = "新增配置图片")
    @PostMapping("add")
    public CommonResult<Boolean> addImgModel(@RequestBody ImgModel imgModel) {
        return CommonResult.success(imgModelService.save(imgModel));
    }


    @Operation(summary = "修改配置图片")
    @PostMapping("update")
    public CommonResult<Boolean> updateImgModel(@RequestBody ImgModel imgModel) {
        if (imgModelService.updateById(imgModel)) {
            return CommonResult.success("修改成功");
        } else {
            return CommonResult.failed("修改失败");
        }
    }

    @Operation(summary = "删除配置图片")
    @PostMapping("delete")
    public CommonResult<Boolean> deleteImgModel(@RequestBody ImgModel imgModel) {
        if (imgModelService.removeById(imgModel)) {
            return CommonResult.success("删除成功");
        } else {
            return CommonResult.failed("删除失败");
        }
    }

}
